package com.arron.command;

import java.util.Stack;

public class RemoteController {
    Command[] offCommands;
    Command[] onCommands;
    //执行撤销命令
    Command undoCommand;
    //构造器，初始化按钮
    public RemoteController() {
        onCommands =new Command[5];
        offCommands =new Command[5];
        for (int i = 0; i < 5; i++) {
            onCommands[i] = new NoCommand();
            offCommands[i] = new NoCommand();
        }
    }

    public void setCommand(int no,Command onCommand,Command offCommand) {
        onCommands[no] = onCommand;
        offCommands[no] = offCommand;
    }

    /**
     * 按下开按钮
     * @param no
     */
    public void onButtonWasPushed(int no) {
        //找到你按下的开的按钮，调用对应的方法
        onCommands[no].execute();
        //记录撤销动作
        undoCommand = onCommands[no];
    }

    /**
     * 按下关按钮
     * @param no
     */
    public void offButtonWasPushed(int no) {
        //找到你按下的开的按钮，调用对应的方法
        offCommands[no].execute();
        //记录撤销动作
        undoCommand = offCommands[no];
    }

    /**
     * 撤销按钮
     */
    public void undoButtonWasPushed(){
        undoCommand.undo();
    }
}
